package com.spring.core.bean;

import com.spring.core.annotation.Component;
import com.spring.core.context.AbstractApplicationContext;

import javax.annotation.*;
import java.lang.annotation.*;

/**
 * 抽像Bean
 *
 * @author Zee
 * @version 1.0
 * @date 2021/10/13
 */
public abstract class AbstractBean {

    public abstract void init(AbstractApplicationContext context);

    /**
     * @param clazz 类
     */
    public boolean hasAnnotationComponent(Class<?> clazz, Boolean isComponentAnnotation) {
        Annotation[] annotations = clazz.getAnnotations();
        for (Annotation annotation : annotations) {
            if (annotation.annotationType() == Deprecated.class ||
                    annotation.annotationType() == SuppressWarnings.class ||
                    annotation.annotationType() == Override.class ||
                    annotation.annotationType() == PostConstruct.class ||
                    annotation.annotationType() == PreDestroy.class ||
                    annotation.annotationType() == Resource.class ||
                    annotation.annotationType() == Resources.class ||
                    annotation.annotationType() == Generated.class ||
                    annotation.annotationType() == Target.class ||
                    annotation.annotationType() == Retention.class ||
                    annotation.annotationType() == Documented.class ||
                    annotation.annotationType() == Inherited.class) {
                continue;
            }
            if (annotation.annotationType() == Component.class) {
                return true;
            } else {
                isComponentAnnotation = hasAnnotationComponent(annotation.annotationType(), isComponentAnnotation);
            }
        }
        return isComponentAnnotation;
    }
}
